using System;
using System.Data;
using System.Collections;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

/// <summary>
/// Summary description for DropDownListHelper
/// </summary>
public partial class ControlHelper
{
    public void FillDataTableToDropDownList(
    DropDownList dropDownList,
    string displayMember,
    string valueMember,
    string selectedValue)
    {

        DataTable dataTable =
        sqlServerProvider.GetDataTable();
        if (dataTable != null)
        {
            dropDownList.DataSource = dataTable;
            dropDownList.DataTextField = displayMember;
            dropDownList.DataValueField = valueMember;
        }
        else
            dropDownList.DataSource = null;
        dropDownList.DataBind();
        if (selectedValue != "")
            dropDownList.SelectedValue = selectedValue;

    }

    public void FillDataTableToDropDownList(
    DropDownList dropDownList1, DropDownList dropDownList2,
    string displayMember1, string displayMember2,
    string valueMember1, string valueMember2,
    string selectedValue1, string selectedValue2)
    {

        DataSet dataSet =
        sqlServerProvider.GetDataSet();
        if (dataSet != null)
        {
            dropDownList1.DataSource = dataSet.Tables[0];
            dropDownList1.DataTextField = displayMember1;
            dropDownList1.DataValueField = valueMember1;

            dropDownList2.DataSource = dataSet.Tables[1];
            dropDownList2.DataTextField = displayMember2;
            dropDownList2.DataValueField = valueMember2;
        }
        else
        {
            dropDownList1.DataSource = null;
            dropDownList2.DataSource = null;
        }
        dropDownList1.DataBind();
        dropDownList2.DataBind();
        if (selectedValue1 != "")
            dropDownList1.SelectedValue = selectedValue1;
        if (selectedValue2 != "")
            dropDownList2.SelectedValue = selectedValue2;

    }

    public void FillDataTableToDropDownList(
    DropDownList dropDownList1, 
    DropDownList dropDownList2, 
    DropDownList dropDownList3,
    string displayMember1, string displayMember2, string displayMember3,
    string valueMember1, string valueMember2, string valueMember3,
    string selectedValue1, string selectedValue2, string selectedValue3)
    {

        DataSet dataSet =
        sqlServerProvider.GetDataSet();
        if (dataSet != null)
        {
            dropDownList1.DataSource = dataSet.Tables[0];
            dropDownList1.DataTextField = displayMember1;
            dropDownList1.DataValueField = valueMember1;

            dropDownList2.DataSource = dataSet.Tables[1];
            dropDownList2.DataTextField = displayMember2;
            dropDownList2.DataValueField = valueMember2;

            dropDownList3.DataSource = dataSet.Tables[2];
            dropDownList3.DataTextField = displayMember3;
            dropDownList3.DataValueField = valueMember3;
        }
        else
        {
            dropDownList1.DataSource = null;
            dropDownList2.DataSource = null;
            dropDownList3.DataSource = null;
        }
        dropDownList1.DataBind();
        dropDownList2.DataBind();
        dropDownList3.DataBind();
        if (selectedValue1 != "")
            dropDownList1.SelectedValue = selectedValue1;
        if (selectedValue2 != "")
            dropDownList2.SelectedValue = selectedValue2;
        if (selectedValue3 != "")
            dropDownList3.SelectedValue = selectedValue3;
    }

    public void FillDataTableToDropDownList(
    DropDownList dropDownList1,
    DropDownList dropDownList2,
    DropDownList dropDownList3,
    DropDownList dropDownList4,
    string displayMember1, string displayMember2, string displayMember3, string displayMember4,
    string valueMember1, string valueMember2, string valueMember3, string valueMember4,
    string selectedValue1, string selectedValue2, string selectedValue3, string selectedValue4)
    {

        DataSet dataSet =
        sqlServerProvider.GetDataSet();
        if (dataSet != null)
        {
            dropDownList1.DataSource = dataSet.Tables[0];
            dropDownList1.DataTextField = displayMember1;
            dropDownList1.DataValueField = valueMember1;

            dropDownList2.DataSource = dataSet.Tables[1];
            dropDownList2.DataTextField = displayMember2;
            dropDownList2.DataValueField = valueMember2;

            dropDownList3.DataSource = dataSet.Tables[2];
            dropDownList3.DataTextField = displayMember3;
            dropDownList3.DataValueField = valueMember3;

            dropDownList4.DataSource = dataSet.Tables[3];
            dropDownList4.DataTextField = displayMember4;
            dropDownList4.DataValueField = valueMember4;
        }
        else
        {
            dropDownList1.DataSource = null;
            dropDownList2.DataSource = null;
            dropDownList3.DataSource = null;
            dropDownList4.DataSource = null;
        }
        dropDownList1.DataBind();
        dropDownList2.DataBind();
        dropDownList3.DataBind();
        dropDownList4.DataBind();
        if (selectedValue1 != "")
            dropDownList1.SelectedValue = selectedValue1;
        if (selectedValue2 != "")
            dropDownList2.SelectedValue = selectedValue2;
        if (selectedValue3 != "")
            dropDownList3.SelectedValue = selectedValue3;
        if (selectedValue4 != "")
            dropDownList4.SelectedValue = selectedValue4;
    }
    
    
    public void FillDataTableToDropDownList(
    DropDownList dropDownList,
    string firstDisplayMember,
    string firstValueMember,
    string displayMember,
    string valueMember,
    string selectedValue)
    {


        DataTable dataTable =
        sqlServerProvider.GetDataTable();

        if (dataTable != null)
        {
            if (firstDisplayMember != "")
            {
                DataRow dataRow = dataTable.NewRow();
                dataRow[0] = firstDisplayMember;
                dataRow[1] = firstValueMember;
                dataTable.Rows.InsertAt(dataRow, 0);
            }
            dropDownList.DataTextField = displayMember;
            dropDownList.DataValueField = valueMember;
            dropDownList.DataSource = dataTable;
            dropDownList.DataBind();
            if (selectedValue != "")
                dropDownList.SelectedValue = selectedValue;
        }
        else
        {
            dropDownList.Items.Add(
            new ListItem(firstDisplayMember,
            firstValueMember));
        }


    }
    void FillStringToDropDownList(
    DropDownList dropDownList,
    string firstDisplayMember,
    string firstValueMember)
    {
        if (firstDisplayMember != "")
        {
            dropDownList.Items.Add(
            new ListItem(firstDisplayMember,
            firstValueMember));
        }
        string[] valueCollection =
        sqlServerProvider.GetStrings();
        for (int i = 0; i < valueCollection.Length; i++)
        {
            dropDownList.Items.Add(
            valueCollection[i]);
        }

    }
    public void FillArrayListToDropDownList(
    DropDownList dropDownList,
    string firstDisplayMember,
    string firstValueMember,
    string selectedValue)
    {


        ArrayList arrayList =
        sqlServerProvider.GetArrayList();
        if (arrayList.Count != 0)
        {
            FillArrayListToDropDownList(
            dropDownList, arrayList,
            firstDisplayMember, firstValueMember);
            if (selectedValue != "")
                dropDownList.SelectedValue =
                selectedValue;
        }


    }
    void FillArrayListToDropDownList(
    DropDownList dropDownList,
    ArrayList arrayList,
    string firstDisplayMember,
    string firstValueMember)
    {
        if (firstDisplayMember != "")
        {
            dropDownList.Items.Add(
            new ListItem(firstDisplayMember,
            firstValueMember));
        }
        for (int i = 0; i < arrayList.Count; i++)
        {
            string[] item = (
            string[])arrayList[i];
            dropDownList.Items.Add(
            new ListItem(item[1], item[0]));
        }

    }
}
